package com.h2.controller;

import com.h2.entity.User;
import com.h2.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/h2")
public class UserController {
    @Autowired
    UserRepository userRepository;

    @PostMapping("/user")
    public String addUser(@RequestBody User user) {
        User savedUser = userRepository.save(user);
        return savedUser.toString();
    }

    @GetMapping("/user")
    public String getUser(@RequestParam String id) {
        User user = userRepository.getOne(id);
        return user.toString();
    }

}
